package com.cyf.app;

import com.cyf.app.network.bean.booking.*;
import com.cyf.app.service.AppBookingService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * app车位预约相关
 * Created by cage on 2017/4/7.
 */
@RestController
@Api("app车位预约相关api")
@RequestMapping(value = "app/booking")
public class AppBookingHttpController {

    @Autowired
    private AppBookingService appBookingService;

    @ApiOperation(value = "获取预约车场列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "longitude", value = "经度", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "latitude", value = "纬度", dataType = "double", required = true, paramType = "query")
    })
    @PostMapping(value = "/getParkings")
    public AppGetParkingsRsp getParkings(@RequestParam String token,
                                         @RequestParam double longitude,
                                         @RequestParam double latitude) {
        AppGetParkingsReq req = new AppGetParkingsReq();
        req.setToken(token);
        req.setLongitude(longitude);
        req.setLatitude(latitude);
        return appBookingService.getParkings(req);
    }

    @ApiOperation(value = "车位预约")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "parkingId", value = "车场id", dataType = "int", required = true, paramType = "query")
    })
    @PostMapping(value = "/booking")
    public AppBookingRsp booking(@RequestParam String token,
                                 @RequestParam Integer parkingId) {
        AppBookingReq req = new AppBookingReq();
        req.setToken(token);
        req.setParkingId(parkingId);
//        return new AppBookingRsp();
        return appBookingService.booking(req);
    }

    @ApiOperation(value = "获取预约列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", dataType = "string", required = true, paramType = "query")
    })
    @PostMapping(value = "/getBookingInfo")
    public AppGetBookingInfoRsp getBookingInfo(@RequestParam String token) {
        AppGetBookingInfoReq req = new AppGetBookingInfoReq();
        req.setToken(token);
        return appBookingService.getBookingInfo(req);
    }

   /* @ApiOperation(value = "获取预约历史列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageNum", value = "页数 从0开始", dataType = "int", required = true, paramType = "query")
    })
    @PostMapping(value = "/getBookingHistory")
    public AppGetBookingHistoryRsp getBookingHistory(@RequestParam String token,
                                                     @RequestParam Integer pageNum) {
        AppGetBookingHistoryReq req = new AppGetBookingHistoryReq();
        req.setToken(token);
        req.setPageNum(pageNum);
        return new AppGetBookingHistoryRsp();
    }*/

    @ApiOperation(value = "取消车位预约")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "bookingId", value = "预约id", dataType = "int", required = true, paramType = "query")
    })
    @PostMapping(value = "/cancelBooking")
    public AppCancelBookingRsp cancelBooking(@RequestParam String token,
                                             @RequestParam Integer bookingId) {
        AppCancelBookingReq req = new AppCancelBookingReq();
        req.setToken(token);
        req.setBookingId(bookingId);
        return appBookingService.cancelBooking(req);
    }
}
